﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;

namespace HostProfiles
{
    static class Program
    {
#if LINUX
		[DllImport ("libc")]
    	public static extern uint getuid ();
#endif
		
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
#if WIN
            bool bMutexCreated = false;
            Mutex mutexMain = new Mutex(true, "my-host-profiles", out bMutexCreated);

            if (!bMutexCreated)
            {
                MessageBox.Show(SR.AlreadyRunning, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
                return;
            }
#endif
			
#if LINUX
			if (getuid() != 0) 
			{
           		MessageBox.Show("Please launch the program with sudo command!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Application.Exit();
                return;
	        }
            //FormPassword pwd = new FormPassword();
            //if (pwd.ShowDialog() == DialogResult.OK)
            //{
            //    Env.Password = pwd.GetPassword();    
            //}
#endif	
			Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Env.Load();
            Application.Run(new FormMain());
        }
    }
}
